<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.min.css" rel="stylesheet" />
		<link href="style/fjol_style.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="style/xol_style.css"/>
	</head>
<style>
	*,.mui-table-view.mui-grid-view .mui-table-view-cell .mui-media-body{
		font-size: 12px;
		color: #555555;
	}
</style>
	<body>
		<header class="mui-bar mui-bar-nav newbgRed" style="box-shadow: none;">
		    <h1 class="mui-title">个人中心</h1>
		</header>
		<div class="mui-content">
			<div class="mui-scroll-wrapper" style="top: 42px;">
				<div class="mui-scroll">
					<!--这里放置真实显示的DOM内容-->
					<div id='loginRegister' class="mui-text-center pt10 pb10 newbgRed">
						<img src="images/user-img.png" width="90" height="90" class="circle" />
						<br />
						<input id='userTitle' type="button" style="color: white;background-color: transparent;border-color: transparent;" value="登录/注册" />
					</div>
					<div class="choose-list buyer-center">
						<p class="bd9 p10" style="border-color: #E0E0E0;">买家中心</p>
						<ul class="mui-table-view mui-grid-view mui-grid-9" style="background: none; border: none;">
							<li class="mui-table-view-cell mui-media mui-col-xs-3 mui-col-sm-3">
								<a id="reservation">
									<span class="mui-icon myIcon-reservation"></span>
									<div class="mui-media-body" style="margin-top: 0;">预约记录</div>
								</a>
							</li>
							<li class="mui-table-view-cell mui-media mui-col-xs-3 mui-col-sm-3">
								<a id="myHouse">
									<span class="mui-icon myIcon-myHouse"></span>
									<div class="mui-media-body" style="margin-top: 0;">收藏房源</div>
								</a>
							</li>
							<li class="mui-table-view-cell mui-media mui-col-xs-3 mui-col-sm-3">
								<a id="mortgageHouse">
									<span class="mui-icon myIcon-mortgageHouse"></span>
									<div class="mui-media-body" style="margin-top: 0;">订阅房源</div>
								</a>
							</li>
							<li class="mui-table-view-cell mui-media mui-col-xs-3 mui-col-sm-3">
								<a id="houseBrowse">
									<span class="mui-icon myIcon-houseBrowse"></span>
									<div class="mui-media-body" style="margin-top: 0;">浏览记录</div>
								</a>
							</li>
							<li class="mui-table-view-cell mui-media mui-col-xs-3 mui-col-sm-3">
								<a id="houseAgent">
									<span class="mui-icon myIcon-houseAgent"></span>
									<div class="mui-media-body" style="margin-top: 0;">我的经纪人</div>
								</a>
							</li>
							<li class="mui-table-view-cell mui-media mui-col-xs-3 mui-col-sm-3">
								<a href="#" id="buyHouseRecord">
									<span class="mui-icon myIcon-selleHouseRecord"></span>
									<!--我的房源-->
									<div class="mui-media-body" style="margin-top: 0;">交易进度</div>
								</a>
							</li>
						</ul>
					</div>

					<div class="choose-list buyer-center mt10">
						<p class="p10 bd9" style="border-color: #E0E0E0;">卖家中心</p>
						<ul class="mui-table-view mui-grid-view mui-grid-9" style="background: none; border: none;">
							<li class="mui-table-view-cell mui-media mui-col-xs-3 mui-col-sm-3">
								<a href="#" id="selleHouseRecord">
									<span class="mui-icon myIcon-selleHouseRecord"></span>
									<!--我的房源-->
									<div class="mui-media-body" style="margin-top: 0;">交易进度</div>
								</a>
							</li>
						</ul>
					</div>

					<div class="mt10">
						<ul class="mui-table-view">
							<li class="mui-table-view-cell">
								<a id="jifenMarket">
									<span class="mui-icon myIcon-mall mr5"></span>
									积分商城
								</a>
							</li>
							<li class="mui-table-view-cell">
								<a id="mortgageCount">
									<span class="mui-icon myIcon-houseLoan mr5"></span>
									房贷计算器
								</a>
							</li>
							<li class="mui-table-view-cell">
								<a class="" data-tel = "4009183588" id="serverPhone">
									<span class="mui-icon myIcon-tel mr5"></span> 联系客服
								</a>
							</li>
							<li class="mui-table-view-cell">
								<a class="" id="feedback">
									<span class="mui-icon myIcon-feedback mr5"></span> 意见反馈
								</a>
							</li>
							<li class="mui-table-view-cell">
								<a class="" id="menuShare">
									<span class="mui-icon myIcon-share mr5"></span> 分享鑫在线
								</a>
							</li>
							<li class="mui-table-view-cell" id="updateVersion">
								<a class="mui-pull-left">
									版本更新
								</a>
								<span class="mui-pull-right">
									当前版本
								</span>
							</li>
						</ul>
					</div>
					
					<div class="f08" align="center" style="margin-top: 1rem;">鑫中正旗下平台</div>
				</div>
			</div>
		</div>
		
		<div id="bottomPopover" class="bottom-popover mui-text-center" style="display: none;">
			<span></span>
			<ul class="mui-table-view mb10">
				<li class="bd9 blue4889c1" id="changePersonMessage">修改个人信息</li>
				<li class="bd9 blue4889c1" id="changePassword">修改密码</li>
				<li class="mui-badge-danger mui-badge-inverted" id="cancelLogin">注销登录</li>
			</ul>
			<ul class="mui-table-view">
				<li class=" blue4889c1" id="hidePopover">取消</li>
			</ul>
		</div>
		<script src="js/mui.min.js"></script>
		<script src="js/fj_public_js.js"></script>
		<!--<script src="js/commonH5.js"></script>-->
		<script src="js/immersed.js" ></script>
		<script src="js/common.util.js"></script>
		<script src="js/enum.util.js"></script>
		<script src='js/md5.js'></script>
		<script src="js/network.js"></script>
		<script src="js/xzx.open.js"></script>
		<script type="text/javascript">
			var isLogined = false;
			mui.init();
			var userInfo;
			var version0;
			var version,versionName;
			var isUpdata,downloadUrl;
			mui.plusReady(function() {
				userInfo = common.myStorage.getItem('userInfo');
				if(userInfo) {
//					console.log(JSON.stringify(userInfo));
					isLogined = true;
					document.querySelector('#userTitle').value = userInfo.realname;
					
				}else{
					isLogined = false;
				}
					
			//检查更新版本
					document.querySelector('#updateVersion').addEventListener('tap',function(){
						if(!isUpdata){
							mui.toast('当前已是最新版本');
						}else{
							mui.confirm('当前版本'+version0+'，最新版本'+version+'，前往下载最新版？','更新版本',['确定','取消'],function(e){
								if(e.index == 0){
									plus.runtime.openURL(downloadUrl);
									
//									var dtask = plus.downloader.createDownload( downloadUrl, 
//										{method:"GET"},
//										function(download, status) {
//										if(download.state == 4) {
//											//下载完成 
//											plus.runtime.openFile(download.filename, {}, function(error) {
//												console.log(error);
//											});
//										}
//									});
//									dtask.addEventListener( "statechanged", function(task,status){
//								    	if(!dtask){return;}
//								    	if(task.state == 1){	//开始下载
//								    		mui.toast('开始下载');
//								    		plus.push.addEventListener( 'receive', function(msg){//添加推送消息事件监听器，当指定推送事件发出时触发。
//								    			mui.toast(msg.content);
//								    		});
//								    	}else if(task.state == 3){	//正在下载
//								    	//	console.log('loading');
//								    	}else if(task.state == 4){	//下载完成
//								    		mui.toast('下载完成');
//								    		var content = '下载完成';
////								    		console.log(content);
//								    		plus.push.createMessage(content);
//								    	}
//								   });
//									dtask.start();
								}
								
							})
						}
					});
					
					/*更新分享服务*/
					updateSerivces();
			});
			
				mui.getJSON("manifest.json",null,function(data){
					
					version0 = parseFloat(data.version.name);		//获取当前版本号
					document.querySelector('#updateVersion span').innerHTML = version0;
					var versionParam = [{
						key:'appType',
						value:1				//版本信息(1 -> 客户版, 2 -> 业务员版)
					},{
						key:'sysType',
						value:2				//版本信息(1 -> ios, 2 -> android)
					}];
					fjNetwork.get('fjzx/common/version-info.json',versionParam,function(data){
//						console.log(JSON.stringify(data));
						version = parseFloat(data.verInfo.version);		//最新版本号
						versionName = data.verInfo.versionDescription;
						downloadUrl = data.verInfo.downloadUrl;
//						console.log(version);
						if(version0 == version){
							document.querySelector('#updateVersion span').innerHTML = '当前版本'+version0+ '已是最新';
							isUpdata = false;					//已是最新版本
						}else if(version0 < version){			//不是最新版本，可以更新到最新
							document.querySelector('#updateVersion span').innerHTML = '当前版本'+version0+ ' 可更新';
							isUpdata = true;
						}
						
					});
					
				});

			//修改个人信息
					document.querySelector('#changePersonMessage').addEventListener('tap',function(){
//						console.log(userInfo.realname);
						openFileWindowWithPage('personal_pages','xol_change_personal',{
							personName:userInfo.realname,
							clientId:userInfo.clientId
						});
					});
					//修改密码
					document.querySelector('#changePassword').addEventListener('tap',function(){
						openFileWindowWithPage('personal_pages','regist',{
							pageTip:'forgetPassword'
						});
					});
					//注销登录
					document.querySelector('#cancelLogin').addEventListener('tap',function(){
						common.myStorage.removeItem('userInfo');
						var wobj = plus.webview.getWebviewById("my_page");
						wobj.reload(true);
					});
			//自定义事件，刷新用户
			document.addEventListener('refreshUserInfo', function() {
//				var userInfo = common.myStorage.getItem('userInfo');
				if(userInfo) {
					isLogined = true;
					document.querySelector('#userTitle').value = userInfo.realname;
				} else {
					isLogined = false;
					document.querySelector('#userTitle').value = '登录/注册';
				}
			});

			document.querySelector('#loginRegister').addEventListener('tap', function() {
				if(!isLogined) {		//未登录跳转登录页面
					openFileWindowWithPage('personal_pages','login',{
								parentId:'my_page'
							});
				}else{					//已登录 popover弹出
					document.querySelector('#bottomPopover').style.display = 'block';
				}
			});
			
			//隐藏popover
			document.querySelector('#hidePopover').addEventListener('tap',function(){
				document.querySelector('#bottomPopover').style.display = 'none';
			});
			
				//预约记录
			document.querySelector('#reservation').addEventListener('tap', function() {
				if(!isLogined){
					mui.confirm('请先登录','提示',['立即登录','取消'],function(e){
						if(e.index == 0){
							openFileWindowWithPage('personal_pages','login',{
								parentId:'my_page'
							});
						}
					});
				}else{
					openFileWindowWithPage('personal_pages','xol_reservation');
					
				}
				
			});

			//收藏房源
			document.querySelector('#myHouse').addEventListener('tap', function() {
				if(!isLogined){
					mui.confirm('请先登录','提示',['立即登录','取消'],function(e){
					if(e.index == 0){
						openFileWindowWithPage('personal_pages','login',{
								parentId:'my_page'
							});
					}
				});
				}else{
				openFileWindowWithPage('personal_pages','xol_collectHouse');
				}
				
			});
			//订阅房源
			document.querySelector('#mortgageHouse').addEventListener('tap', function() {
				if(!isLogined){
					mui.confirm('请先登录','提示',['立即登录','取消'],function(e){
					if(e.index == 0){
						openFileWindowWithPage('personal_pages','login',{
								parentId:'my_page'
							});
					}
				});
				}else{
				openFileWindowWithPage('personal_pages','mortgage_house');
				}
				
			});
			//浏览记录==========页面与收藏房源、订阅房源一样
			document.querySelector('#houseBrowse').addEventListener('tap',function(){
				if(!isLogined){
					mui.confirm('请先登录','提示',['立即登录','取消'],function(e){
					if(e.index == 0){
						openFileWindowWithPage('personal_pages','login',{
								parentId:'my_page'
							});
					}
				});
				}else{
				openFileWindowWithPage('personal_pages','house_browse');
				}
				
			});

			//我的经纪人
			document.querySelector('#houseAgent').addEventListener('tap', function() {
				if(!isLogined){
					mui.confirm('请先登录','提示',['立即登录','取消'],function(e){
					if(e.index == 0){
						openFileWindowWithPage('personal_pages','login',{
								parentId:'my_page'
							});
					}
				});
				}else{
				openFileWindowWithPage('personal_pages','xol_agent');
				}
				
			});
			//交易进度==============同上房源
			document.querySelector('#selleHouseRecord').addEventListener('tap',function(){
				if(!isLogined){
					mui.confirm('请先登录','提示',['立即登录','取消'],function(e){
					if(e.index == 0){
						openFileWindowWithPage('personal_pages','login',{
								parentId:'my_page'
							});
					}
				});
				}else{
				openFileWindowWithPage('personal_pages','xol_entrust');
				}
				
			});
			//买家交易进度
			document.querySelector('#buyHouseRecord').addEventListener('tap',function(){
				if(!isLogined){
					mui.confirm('请先登录','提示',['立即登录','取消'],function(e){
					if(e.index == 0){
						openFileWindowWithPage('personal_pages','login',{
								parentId:'my_page'
							});
					}
				});
				}else{
				openFileWindowWithPage('personal_pages','xol_entrust');
				}
				
			});
			
			//房价计算器
			document.querySelector('#mortgageCount').addEventListener('tap',function(){
				openFileWindowWithPage('buy_house','fj_mortgage',{
							allPayment:179
						});
			});

			//意见反馈
			document.querySelector('#feedback').addEventListener('tap', function() {
				if(!isLogined){
					mui.confirm('请先登录','提示',['立即登录','取消'],function(e){
					if(e.index == 0){
						openFileWindowWithPage('personal_pages','login',{
								parentId:'my_page'
							});
					}
				});
				}else{
				openFileWindowWithPage('personal_pages','feedback');
				}
				
			});
			
						
			//拨打电话处理按钮
			document.querySelector("#serverPhone").addEventListener('tap', function() {
				if(!isLogined){
					mui.confirm('请先登录','提示',['立即登录','取消'],function(e){
					if(e.index == 0){
						openFileWindowWithPage('personal_pages','login',{
								parentId:'my_page'
							});
					}
				});
				}else{
					var btnArray = ['拨打', '取消'];
//					var mobile = this.getAttribute('data-tel');
					var mobile = '4009183588';
					mui.confirm('是否拨打' + mobile + '?', '提示', btnArray, function(e) {
						if(e.index == 0) {
							plus.device.dial(mobile, false);
						}
					});
				}
				
			});
			
			/*积分商城*/
			document.querySelector('#jifenMarket').addEventListener('tap',function(){
				if(!isLogined){
					mui.confirm('请先登录','提示',['立即登录','取消'],function(e){
					if(e.index == 0){
						openFileWindowWithPage('personal_pages','login',{
								parentId:'my_page'
							});
					}
				});
				}else{
					var mobile = userInfo.mobile;
					var password = userInfo.password;
					var datas = [{
						key: 'mobile',
						value: mobile
					},{
						key: 'password',
						value: password
					}];
					var sign = fjNetwork.signParam(datas);
	
					var jifenUrl = 'http://www.xinzhongzheng.com/credit/appViewController.do?index&mobile='+mobile+'&password='+password+'&sign='+sign;
					mui.openWindow({
						url: 'jifenMall.html',
						id: 'jifenMall',
						extras: {
							mallUrl:jifenUrl
						}
					})
				}
				
			});
			
			/*分享鑫在线*/
			document.querySelector('#menuShare').addEventListener('tap',function(){
					
				var ids = [{
                    id: "weixin", 
                    ex: "WXSceneSession"  /*微信好友*/
                }, {
                    id: "weixin",
                    ex: "WXSceneTimeline" /*微信朋友圈*/
                }
//              , {
//                  id: "qq"   /*QQ好友*/
//              }
                ],
                bts = [{
                    title: "发送给微信好友"
                }, {
                    title: "分享到微信朋友圈"
                }
//              , {
//                  title: "分享到QQ"
//              }
                ];
	            plus.nativeUI.actionSheet({
	                    cancel: "取消",
	                    buttons: bts
	                },
	                function(e) {
	                    var i = e.index;
	                    if (i > 0) {
	                        shareAction(ids[i - 1].id, ids[i - 1].ex);
	                    }
	                }
	            );
	            
			});
			/**
         * 分享操作
         */
        function shareAction(id, ex) {
            var s = null;
            if (!id || !(s = shares[id])) {
                outLine("无效的分享服务！");
                return;
            }
            if (s.authenticated) {
                outSet("---已授权---");
                shareMessage(s, ex);
            } else {
                outSet("---未授权---");
                s.authorize(function() {
                    shareMessage(s, ex);
                }, function(e) {
                    outLine("认证授权失败");
                });
            }
        }
        /**
         * 发送分享消息
         */
        function shareMessage(s, ex) {
            var msg = {
                content: '分享-鑫在线',
                href: 'http://android.myapp.com/myapp/detail.htm?apkName=com.wztz.xzx',
                title: '鑫在线',
                content: '本地优质生活平台',
                thumbs: ['images/logo512x512.png'],
                pictures: ['images/logo512x512.png'],
                extra: {
                    scene: ex
                }
            };
            s.send(msg, function() {
                outLine("分享成功!");
                
                //登录状态下 分享成功增加积分
                if(isLogined){
                	shareSuccess();
                }
                
            }, function(e) {
                outLine("分享失败!");
            });
        }
        /**
         * 更新分享服务
         */
        function updateSerivces() {
            plus.share.getServices(function(s) {
                shares = {};
                for (var i in s) {
                    var t = s[i];
                    shares[t.id] = t;
                }
                outSet("获取分享服务列表成功");
            }, function(e) {
                outSet("获取分享服务列表失败：" + e.message);
            });
        }
        // 控制台输出日志
        function outSet(msg) {
            console.log(msg);
        }
        // 界面弹出吐司提示
        function outLine(msg) {
            mui.toast(msg);
        }
        /*分享成功*/
       function shareSuccess(){
//	       	console.log(userInfo.clientId);
	       	var shareParam = [{
	        	key:'clientId',
	        	value:userInfo.clientId
	        }]
	        fjNetwork.post('fjzx/client/add-app-share-integral.json',shareParam,function(data){
//	        	console.log(JSON.stringify(data));
	        });
       }
		</script>
	</body>

</html>